<template>
  <base-breadcrumb  :breadcrumb="!isAudit">
    <a-card :bordered="false">
      <title-name title="基础信息"></title-name>
      <a-row :gutter="24">
        <a-col :md="16" :sm="16">
          <a-form-item
                  label="所属单位"
                  :labelCol="{ lg: { span: 7 }, sm: { span: 7 } }"
                  :wrapperCol="{ lg: { span: 17 }, sm: { span: 17 } }"
          >
          <org-tree-select disabled :value="dels.projectId"></org-tree-select>
          </a-form-item>
        </a-col>
<!--        <a-col :md="8" :sm="8">-->
<!--          <a-form-item-->
<!--            label="分公司"-->
<!--            :labelCol="{ lg: { span: 7 }, sm: { span: 7 } }"-->
<!--            :wrapperCol="{ lg: { span: 17 }, sm: { span: 17 } }"-->
<!--          >-->
<!--            <BaseInput v-model="dels.branchCompanyName" type="text" disabled></BaseInput>-->
<!--          </a-form-item>-->
<!--        </a-col>-->
<!--        <a-col :md="8" :sm="8">-->
<!--          <a-form-item-->
<!--            label="项目"-->
<!--            :labelCol="{ lg: { span: 7 }, sm: { span: 7 } }"-->
<!--            :wrapperCol="{ lg: { span: 17 }, sm: { span: 17 } }"-->
<!--          >-->
<!--            <BaseInput v-model="dels.projectName" type="text" disabled></BaseInput>-->
<!--          </a-form-item>-->
<!--        </a-col>-->
        <a-col :md="8" :sm="8">
          <a-form-item
            label="项目编号"
            :labelCol="{ lg: { span: 7 }, sm: { span: 7 } }"
            :wrapperCol="{ lg: { span: 17 }, sm: { span: 17 } }"
          >
            <BaseInput v-model="dels.projectNum" type="text" disabled></BaseInput>
          </a-form-item>
        </a-col>
      </a-row>
      <a-row :gutter="24">
        <a-col :md="8" :sm="8">
          <a-form-item
            label="项目经理名称"
            :labelCol="{ lg: { span: 7 }, sm: { span: 7 } }"
            :wrapperCol="{ lg: { span: 17 }, sm: { span: 17 } }"
          >
            <BaseInput v-model="dels.projectManager" type="text" disabled></BaseInput>
          </a-form-item>
        </a-col>
        <a-col :md="8" :sm="8">
          <a-form-item
            label="积分年份"
            :labelCol="{ lg: { span: 7 }, sm: { span: 7 } }"
            :wrapperCol="{ lg: { span: 17 }, sm: { span: 17 } }"
          >
            <!--<BaseInput v-model="dels.projectName" type="text" ></BaseInput>-->
            <a-select
              v-model="dels.yearOfIntegral"
              :disabled="type == 'approve' || this.isConsultation"
              @change="getBasicInfo"
              style="width: 100%"
            >
              <a-select-option v-for="item in yearPoints" :value="item" :key="item">{{ item }}</a-select-option>
            </a-select>
          </a-form-item>
        </a-col>
        <a-col :md="8" :sm="8">
          <a-form-item
            label="本年剩余分数"
            :labelCol="{ lg: { span: 7 }, sm: { span: 7 } }"
            :wrapperCol="{ lg: { span: 17 }, sm: { span: 17 } }"
          >
            <a-input-number
              disabled
              :min="0"
              :max="9999999999999"
              :step="1"
              v-model="dels.currentResidualFraction"
              :precision="2"
            />
            <!-- <BaseInput v-model="dels.currentResidualFraction" type="text" disabled></BaseInput> -->
          </a-form-item>
        </a-col>
      </a-row>
      <a-row :gutter="24">
        <a-col :md="8" :sm="8">
          <a-form-item
            label="本年已扣分数"
            :labelCol="{ lg: { span: 7 }, sm: { span: 7 } }"
            :wrapperCol="{ lg: { span: 17 }, sm: { span: 17 } }"
          >
            <a-input-number
              disabled
              :min="0"
              :max="9999999999999"
              :step="1"
              v-model="dels.pointsDeductedThisYear"
              :precision="2"
            />
            <!-- <BaseInput v-model="dels.pointsDeductedThisYear" type="text" disabled></BaseInput> -->
          </a-form-item>
        </a-col>
        <a-col :md="8" :sm="8">
          <a-form-item
            label="提示"
            :labelCol="{ lg: { span: 7 }, sm: { span: 7 } }"
            :wrapperCol="{ lg: { span: 17 }, sm: { span: 17 } }"
          >
            <!--<BaseInput v-model="dels.promptSituationCode" type="text" disabled></BaseInput>-->
            <div v-if="dels.promptSituationCode == '0'" class="noneInfo">无</div>
            <div v-if="dels.promptSituationCode == '1'" class="promptSituationCode gray"></div>
            <div v-if="dels.promptSituationCode == '2'" class="promptSituationCode yellow"></div>
            <div v-if="dels.promptSituationCode == '3'" class="promptSituationCode red"></div>
          </a-form-item>
        </a-col>
      </a-row>

      <title-name title="扣分信息"></title-name>
      <a-table
        bordered
        :pagination="false"
        :scroll="{ x: 1500 }"
        ref="table"
        size="default"
        :rowKey="(record) => record.id"
        :columns="columns"
        :data-source="pointScore"
        :alert="true"
        show-size-changer
        show-quick-jumper
        showPagination="auto"
      >
        <span slot="serial" slot-scope="text, record, index">{{ index + 1 }}</span>
        <span slot="pointsScore" slot-scope="text, record, index">{{ Number(record.pointsScore).toFixed(2) }}</span>
        <span slot="pointDeductionReason" slot-scope="text">
          <ellipsis :length="50" tooltip>{{ text }}</ellipsis>
        </span>
        <span slot="createTime" slot-scope="text, record, index">
          {{ record.createTime.trim().split(' ')[0] }}
        </span>
        <span slot="action" slot-scope="text, record, index">
          <a @click="handleRecord(record)">查看</a>
        </span>
      </a-table>
      <pagination
        :total="totalSize"
        v-model="pageNo"
        :pageSize.sync="pageSize"
        @change="handlePageChange"
        @showSizeChange="showSizeChange"
      ></pagination>

      <a-modal width="900px" v-if="visible" @cancel="visible = false" :visible="true" :title="'扣分详细信息'">
        <template slot="footer">
          <a-button key="back" @click="handleCancel"> 关闭 </a-button>
        </template>
        <a-form :model="form">
          <a-row>
            <a-col :md="12" :sm="12">
              <a-form-item
                label="扣分分数"
                :labelCol="{ lg: { span: 5 }, sm: { span: 5 } }"
                :wrapperCol="{ lg: { span: 18 }, sm: { span: 18 } }"
              >
                <a-input-number
                  disabled
                  :min="0"
                  :max="9999999999999"
                  :step="1"
                  v-model="form.pointsScore"
                  :precision="2"
                />
                <!-- <BaseInput v-model="form.pointsScore" disabled></BaseInput> -->
              </a-form-item>
            </a-col>
            <a-col :md="12" :sm="12">
              <a-form-item
                label="创建人"
                :labelCol="{ lg: { span: 5 }, sm: { span: 5 } }"
                :wrapperCol="{ lg: { span: 18 }, sm: { span: 18 } }"
              >
                <BaseInput v-model="form.creatorName" disabled></BaseInput>
              </a-form-item>
            </a-col>
          </a-row>
          <a-row>
            <a-col :md="12" :sm="12">
              <a-form-item
                label="创建时间"
                :labelCol="{ lg: { span: 5 }, sm: { span: 5 } }"
                :wrapperCol="{ lg: { span: 18 }, sm: { span: 18 } }"
              >
                <BaseInput v-model="form.createTime" disabled></BaseInput>
              </a-form-item>
            </a-col>
          </a-row>
          <a-row>
            <a-col :md="24" :sm="24">
              <a-form-item
                label="风险底线事件"
                :labelCol="{ lg: { span: 5 }, sm: { span: 5 } }"
                :wrapperCol="{ lg: { span: 18 }, sm: { span: 18 } }"
              >
                <BaseInput v-model="form.pointDeductionReason" type="textarea" disabled></BaseInput>
              </a-form-item>
            </a-col>
          </a-row>
          <a-row>
            <a-col :md="24" :sm="24">
              <a-form-item
                label="处罚认定"
                :labelCol="{ lg: { span: 5 }, sm: { span: 5 } }"
                :wrapperCol="{ lg: { span: 18 }, sm: { span: 18 } }"
              >
                <BaseInput v-model="form.remark" type="textarea" disabled></BaseInput>
              </a-form-item>
            </a-col>
          </a-row>
          <title-name title="证明材料"></title-name>
          <a-table rowKey="id" bordered :columns="columnAssment" :data-source="form.fileInfoIds">
            <span slot="serial" slot-scope="text, record, index">{{ index + 1 }}</span
            ><span slot="action" slot-scope="text, record, index">
              <a
                :href="'/api/ycloud-file-center/oper/download?access_token=' + token + '&fileId=' + record.fileId"
                target="_parent"
                >导出</a
              >
              <a-divider type="vertical" />
              <a href="javascript:" @click="$filePreview(record)">预览</a>
            </span>
          </a-table>
        </a-form>
      </a-modal>

      <title-name title="恢复分数信息" v-if="statusCode == 1" style="margin-top: 20px"></title-name>
      <a-table
        v-if="statusCode == 1"
        :pagination="false"
        bordered
        ref="table"
        size="default"
        :rowKey="(record) => record.id"
        :columns="columnInfo"
        :data-source="scoresData"
        :alert="true"
        show-size-changer
        show-quick-jumper
        showPagination="auto"
      >
        <span slot="serial" slot-scope="text, record, index">{{ index + 1 }}</span>
        <span slot="description" slot-scope="text, record, index">
          <ellipsis :length="80" tooltip>{{ text }}</ellipsis>
        </span>
      </a-table>
      <pagination
        v-if="statusCode == 1"
        :total="totalSize1"
        v-model="pageNo1"
        :pageSize.sync="pageSize1"
        @change="handlePageChange1"
        @showSizeChange="showSizeChange1"
      ></pagination>
    </a-card>

    <div v-if="!isConsultation" class="page-btn-right-top">
      <a-button type="primary" @click="goBack">关闭</a-button>
    </div>
  </base-breadcrumb>
</template>

<script>
import Vue from 'vue'
import { STable, Ellipsis } from '@/components'
import { getIntegralDetails, getIntegralYearPoint, getRestoreList, getIntegralRestoreId } from '@/api/project/integral'
import { getPointsRecordList, getPointsRecordDetails } from '@/api/project/pointsRecord'
import SelectSubCompany from '@/components/Select/SelectSubCompany' // 分公司
import SelectProject from '@/components/Select/SelectProject' // 项目

import ARow from 'ant-design-vue/es/grid/Row'

const columns = [
  {
    title: '序号',
    width: 65,

    scopedSlots: { customRender: 'serial' }
  },
  {
    title: '扣分分数',

    dataIndex: 'pointsScore',
    scopedSlots: { customRender: 'pointsScore' }
  },
  {
    title: '风险底线事件',
    dataIndex: 'pointDeductionReason',
    scopedSlots: { customRender: 'pointDeductionReason' }
  },
  {
    title: '创建人',

    dataIndex: 'creatorName'
  },
  {
    title: '创建时间',
    dataIndex: 'createTime',
    scopedSlots: { customRender: 'createTime' }
  },
  {
    title: '操作',
    dataIndex: 'action',

    scopedSlots: { customRender: 'action' }
  }
]

const columnInfo = [
  {
    title: '序号',
    width: 65,
    scopedSlots: { customRender: 'serial' }
  },
  {
    title: '恢复分数说明',
    dataIndex: 'description',
    scopedSlots: { customRender: 'description' }
  },
  {
    title: '创建人',
    dataIndex: 'creatorName'
  },
  {
    title: '创建时间',
    dataIndex: 'createTime'
  }
]

const columnAssment = [
  {
    title: '序号',
    width: 65,
    dataIndex: 'serial',

    scopedSlots: { customRender: 'serial' }
  },
  {
    title: '附件名称',
    dataIndex: 'fileName'
  },
  {
    title: '附件格式',
    dataIndex: 'suffixName',
    width: '25%'
  },
  {
    title: '操作',
    key: 'action',
    width: '20%',
    scopedSlots: { customRender: 'action' }
  }
]

export default {
  name: 'a' + Date.now(),
  components: {
    ARow,
    Ellipsis
  },
  props: {
      // 是否作为审批详情
      isAudit: {
        type: Boolean,
        default: false
      },
      // 是否作为意见征询
      isConsultation: {
        type: Boolean,
        default: false
      }
    },
  data() {
    return {
      columns, // 扣分信息
      columnAssment, // 附件信息
      columnInfo, //  恢复分数信息

      businessId: '',
      token: '',

      pageNo: 1,
      pageSize: 10,
      totalSize: 0,

      pageNo1: 1,
      pageSize1: 10,
      totalSize1: 0,

      statusCode: null,
      scoresData: [], // 恢复分数
      pointScore: [], // 扣分信息
      visible: false,
      title: '',

      dels: {}, // 项目经理积分详情
      yearPoints: [], // 积分年份

      form: {}, // 表单
      type: '' // 类型
    }
  },

  created() {
    this.id = this.$route.query.id
    this.type = this.$route.query.type
    this.token = Vue.getAcloudProvider().getAccessToken()
    this.getIntegralDetailsReq()
  },
  computed: {},
  methods: {
    // 分页参数查询
    handlePageChange(pageNo) {
      this.pageNo = pageNo
      this.getIntegralYearPointReq()
    },
    showSizeChange(pageNo, pageSize) {
      this.pageNo = 1
      this.pageSize = pageSize
      this.getIntegralYearPointReq()
    },

    handlePageChange1(pageNo) {
      this.pageNo1 = pageNo
      this.getIntegralYearPointReq()
    },
    showSizeChange1(pageNo, pageSize) {
      this.pageNo1 = 1
      this.pageSize1 = pageSize
      this.getIntegralYearPointReq()
    },

    goBack() {
      // 关闭
      if (this.type == 'approve') {
        window.close()
      } else {
        this.$multiTab.close(this.$route.fullpath)
      }
    },
    // 查询项目经理积分基础信息详情
    getIntegralDetailsReq() {
      let that = this

      if (this.type == 'approve' || this.isConsultation) {
        getIntegralRestoreId({ id: this.id }).then((res) => {
          if (res.code == 200) {
            that.dels = res.data
            that.getIntegralYearPointReq()
          }
        })
      } else {
        getIntegralDetails({ id: this.id }).then((res) => {
          if (res.code == 200) {
            that.dels = res.data
            that.getIntegralYearPointReq()
          }
        })
      }
    },

    getIntegralYearPointReq() {
      let that = this
      // 查询积分年份
      getIntegralYearPoint({ projectManagerId: that.dels.projectManagerId, projectId: that.dels.projectId }).then(
        (datas) => {
          if (datas.code == 200) {
            that.yearPoints = datas.data

            let id = ''
            if (that.type == 'approve' || this.isConsultation) {
              id = that.dels.id
            } else {
              id = that.id
            }

            // 查询恢复分数
            getRestoreList({
              status: 2,
              managerScoreId: id,
              yearOfIntegral: that.dels.yearOfIntegral,
              pageNo: 1,
              pageSize: 20
            }).then((socore) => {
              if (socore.code == 200) {
                that.scoresData = socore.data
                that.totalSize1 = socore.totalSize
                if (socore.data.length > 0) {
                  that.statusCode = 1
                }
              }
            })

            // 查询扣分信息
            getPointsRecordList({
              status: 2,
              managerScoreId: id,
              yearOfIntegral: that.dels.yearOfIntegral,
              pageNo: 1,
              pageSize: 20
            }).then((points) => {
              if (points.code == 200) {
                that.pointScore = points.data
                that.totalSize = points.totalSize
              }
            })
          }
        }
      )
    },

    // 查询不同积分年份的信息
    getBasicInfo(val) {
      let that = this

      let id = ''
      if (that.type == 'approve' || this.isConsultation) {
        id = that.dels.id
      } else {
        id = that.id
      }

      // 查询恢复分数
      getRestoreList({ status: 2, managerScoreId: id, yearOfIntegral: val, pageNo: 1, pageSize: 20 }).then((socore) => {
        if (socore.code == 200) {
          that.scoresData = socore.data
          that.totalSize1 = socore.totalSize
          if (socore.data.length > 0) {
            that.statusCode = 1
          }
        }
      })

      // 查询扣分信息
      getPointsRecordList({ status: 2, managerScoreId: id, yearOfIntegral: val, pageNo: 1, pageSize: 20 }).then(
        (points) => {
          if (points.code == 200) {
            that.pointScore = points.data
            that.totalSize = points.totalSize
          }
        }
      )
    },

    handleRecord(e) {
      // 查看年度评级想详情
      getPointsRecordDetails({ id: e.id }).then((res) => {
        if (res.code == 200) {
          this.visible = true
          this.form = { ...res.data }
          this.form.createTime = res.data.createTime.trim().split(' ')[0]
        }
      })
    },

    // 取消弹层
    handleCancel() {
      this.visible = false
    }
  }
}
</script>

<style scoped>
.promptSituationCode {
  width: 90px;
  height: 35px;
  border-radius: 5px;
}
.promptSituationCode.gray {
  background-color: rgba(215, 215, 215, 1);
}
.promptSituationCode.yellow {
  background-color: rgba(255, 255, 76, 1);
}
.promptSituationCode.red {
  background-color: rgba(240, 153, 164, 1);
}
.noneInfo {
  line-height: 35px;
}
</style>

